package mybatis;

import cn.itcast.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class Mybatis {
    public static void main(String[] args) throws IOException {
             //获取全局局配置文件输入流
        InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
                       //加载全局配置文件
        SqlSessionFactory sql = new SqlSessionFactoryBuilder().build(inputStream);
                  //获取sqlseeion
        SqlSession sqlSession = sql.openSession();
              //第一个参数为命名空间
           //第二个参数为传递的sql语句
                User u= sqlSession.selectOne("UserMapper.QueryById",1L);
        System.out.println(u);
          sqlSession.close();
    }
}
